package com.my.vote.repository;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.my.vote.entity.VoteQuestion;

public interface VoteQuestionRepository extends JpaRepository<VoteQuestion, String> {

	@Query(value = " select q from VoteQuestion q where q.delFlag = 0 and q.subjectId =?1 order by q.orderNum asc ")
	List<VoteQuestion> findAllBySubjectId(String subjectId);

	@Transactional
	@Modifying(clearAutomatically = true)
	@Query(value = " update VoteQuestion q set q.delFlag = 1 where q.delFlag = 0 and q.subjectId =?1 ")
	void deleteAllBySubjectId(String subjectId);

	@Transactional
	@Modifying(clearAutomatically = true)
	@Query(value = " update VoteQuestion q set q.delFlag = 1 where q.delFlag = 0 and q.id =?1 ")
	void deleteById(String id);
}
